package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.OverdueConfigApiService;
import com.yixun.qfbao.apidto.CheckReportProtectReqDto;
import com.yixun.qfbao.apidto.CheckReportProtectResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.OverdueConfig;
import com.yixun.qfbao.model.dto.OverdueConfigDto;
import com.yixun.qfbao.service.OverdueConfigService;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.CheckReportProtectReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import com.yixun.qfbao.xf.service.PremisesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CheckReportProtectHander extends CommonAbstractHander {

    private static final Logger logger = LoggerFactory.getLogger(CheckReportProtectHander.class);
    @Autowired
    private OverdueConfigApiService overdueConfigApiService;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO baseRequestDTO) {
        CheckReportProtectReqVo reqVo = (CheckReportProtectReqVo) baseRequestDTO;
        CheckReportProtectReqDto reqDto = reqVo.getParams();
        BaseResponseDTO<CheckReportProtectResDto> res = new BaseResponseDTO<>();
        CheckReportProtectResDto resDto = new CheckReportProtectResDto();
        try {
            List<Map<String, String>> list = overdueConfigApiService.checkReportProtect(reqDto);
            resDto.setList(list);
            resDto.setResult(ResultEnum.SUCCESS.getNo());
        } catch (TServerException te) {
            logger.error("CheckReportProtectHander TServerException error: {}", te);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg(te.getErrorMsg());
        } catch (Exception e) {
            logger.error("CheckReportProtectHander error: {}", e);
            res.setResult(resDto.getResult());
            res.setErrorMsg("系统异常");
        }
        res.setResult(resDto.getResult());
        res.setResData(resDto);
        return res;
    }
}
